package test.android;

public class VolumeController {
	private float oriValue;
	private boolean isStart;
	private float lastDiff;
	private float volume = (float) 0.1;
	private boolean hasSet;

	public VolumeController() {
		this.isStart = false;
		this.hasSet = false;
	}

	public float getVolume() {
		return volume;
	}

	public boolean isSet() {
		return hasSet;
	}

	public void setStart() {
		this.isStart = false;
	}
	
	public void setHasSet() {
		this.hasSet = false;
	}

	public void setVolume(float curValue1, float curValue2, float curValue3) {
		long curTime;
		if (!isStart) {
			oriValue = (float) Math.pow((Math.abs(curValue1)*Math.abs(curValue1) + Math.abs(curValue2)*Math.abs(curValue2)
					+ Math.abs(curValue3)*Math.abs(curValue3)),2);
			lastDiff = 0;
			isStart = true;
		} else {
				float curValue = (float) Math.pow((Math.abs(curValue1)*Math.abs(curValue1) + Math.abs(curValue2)*Math.abs(curValue2)
				+ Math.abs(curValue3)*Math.abs(curValue3)),2);
				float curDiff = (float) Math.abs(curValue - oriValue);
				if (curDiff < lastDiff) {
					if (lastDiff > 3000)
						volume = (float) 1.0;
					else if (lastDiff > 2000)
						volume = (float) 0.8;
					else if (lastDiff > 1500)
						volume = (float) 0.6;
					else if (lastDiff > 800)
						volume = (float) 0.4;
					else
						volume = (float) 0.2;
					hasSet = true;
				} else
					lastDiff = curDiff;
		}
	}

}